package com.happyscan138.makefun;

import android.app.Activity;
import android.content.Intent;
import android.content.pm.ActivityInfo;
import android.content.res.Configuration;
import android.os.Bundle;
import android.view.KeyEvent;

import com.happyscan138.makefun.Urls.Urls;
import com.happyscan138.makefun.base.VideoPlayView;

import static com.loopj.android.http.AsyncHttpClient.log;

/**
 * Created by Administrator on 2017/3/15.
 */

public class VideoviewPlay extends Activity {
    private String resource;
    private VideoPlayView videoPlayView;
    private Intent intent;
    private String u3m8;
    private String thumb;

     @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
//        requestWindowFeature(Window.FEATURE_NO_TITLE);
//       getWindow().setFlags(WindowManager.LayoutParams.TYPE_STATUS_BAR, WindowManager.LayoutParams.TYPE_STATUS_BAR);
        setContentView(R.layout.video);
         initView();
         intent=getIntent();
         resource=intent.getStringExtra("url");
         u3m8=intent.getStringExtra("u3m8");
         thumb=intent.getStringExtra("Thumb");
//         Log.e("u3m8",u3m8);
//         Log.e("u3m8",resource);
         IO();

    }
    public  void  initView(){
        videoPlayView=(VideoPlayView)findViewById(R.id.vidoe);

    }
    private void IO(){
        if(u3m8!=null) {
            try {
                Thread.sleep(500);
                if (u3m8.equals(Urls.base)) {
                    videoPlayView.setUrl(resource);
                    videoPlayView.setThumb(thumb);
                } else {
                    videoPlayView.setUrl(u3m8);
                    videoPlayView.setThumb(thumb);
                }
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }else{
            videoPlayView.setUrl(resource);
            videoPlayView.setThumb(thumb);
        }
    }

    /**
     * 当窗口处于横屏时,点击返回键退出横屏
     * @param keyCode
     * @param event
     * @return
     */

    public boolean onKeyDown(int keyCode, KeyEvent event) {
        if (keyCode == KeyEvent.KEYCODE_BACK) {
            if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE) {
                setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
                log.e("onKeyDown","onKeyDown");
                return true;
            }
        }
        return super.onKeyDown(keyCode, event);
    }

}
